package violin;

public class Configuration {
    private String resourceRoot;

    public String getResourcePath(Class<?> resourceClass) {
        String clazzName = resourceClass.getName();//org.webdemo.resources.hr.Record
        int index = clazzName.lastIndexOf(".");
        String path = clazzName.replaceFirst(resourceRoot, "").substring(1).substring(0, index);//hr
        String resourceName = resourceClass.getSimpleName();
        resourceName = resourceName.replaceFirst("Resource", "");
        resourceName = Character.toLowerCase(resourceName.charAt(0)) + resourceName.substring(1);
        return (path + "." + resourceName).replaceAll("\\.", "/");//hr/record
    }

    public String getResourceRoot() {
        return resourceRoot;
    }

    public void setResourceRoot(String resourceRoot)
    {
        this.resourceRoot = resourceRoot; 
    }
    public static String resolveClassAlias(Class clazz) {
        String clazzName = clazz.getSimpleName();
        return Character.toLowerCase(clazzName.charAt(0)) + clazzName.substring(1);
    }
}
